package com.thread.book.book2;

import org.junit.Test;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.LockSupport;

public class Book08 {

    public static void main(String[] args) throws InterruptedException {
        new Thread(() -> {
            LockSupport.unpark(Thread.currentThread());
            LockSupport.park(Thread.currentThread());
            System.out.println("--------------");
        }).start();
        TimeUnit.SECONDS.sleep(2);
    }

    @Test
    public void testRetry() {
        retry:
        for (int i = 0; i < 2; i++) {
            for (int j = 0; j < 5; j++) {
                System.out.println(j);
                if (j == 3) continue retry;//继续执行下一次retry标记的循环,即i=1开始
            }
        }
    }

    @Test
    public void testRetry01() {
        retry:
        //此标志可自定义 a b  c 都可以
        for (int i = 0; i < 2; i++) {
            for (int j = 0; j < 5; j++) {
                System.out.println(j);
                if (j == 3) break retry;//直接退出retry标记的循环
            }
        }
    }


    @Test
    public void test001() throws InterruptedException {
        int sum = 0;
        long start = System.currentTimeMillis();
        for (int i = 1; i <= 4; i++) {
            TimeUnit.SECONDS.sleep(1);
            sum += i;
        }
        long end = System.currentTimeMillis();
        System.out.println(sum);
        System.out.println(end - start);
    }
}
